﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CommunicationDataContract;
using System.ServiceModel;
using System.Threading;

namespace CommunicationServiceApplication
{
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
    public class WindowsServiceCommunicationEndPoint : IWindowsServiceCommunicationEndPointContract
    {
        public Boolean IsJobPaused(Guid attachedApplicationId)
        {
            WindowsServiceController.Instance.Security(attachedApplicationId);
            return (WindowsServiceController.Instance.LastAction < DateTime.Now.Subtract(new TimeSpan(0, 0, 9)));
        }

        public void JobStart(Guid attachedApplicationId)
        {
            WindowsServiceController.Instance.Security(attachedApplicationId);
            WindowsServiceController.Instance.IsWindowsServiceActive = true;
        }

        public void JobPause(Guid attachedApplicationId)
        {
            WindowsServiceController.Instance.Security(attachedApplicationId);
            WindowsServiceController.Instance.IsWindowsServiceActive = false;
        }

        public Guid[] AttachedApplications(Guid attachedApplicationId)
        {
            WindowsServiceController.Instance.Security(attachedApplicationId);
            return WindowsServiceController.Instance.GetAttachedApplicationIds();
        }
    }
}
